package com.ruoyi.tiktok.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.tiktok.domain.TFolder;
import org.apache.ibatis.annotations.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface FolderMapper extends BaseMapper<TFolder> {

    /**
     * 文件列表
     */

    //@ResultMap("mFolder")
    @Results(id = "tFolder",
            value={
                    @Result( column = "folder_Id", property ="folderId"),
                    @Result( column = "folder_name", property ="folderName"),
                    @Result( column = "create_time", property ="createTime"),
                    @Result( column = "create_by", property ="createBy")}
    )
    @Select("select f.folder_id ,f.folder_name, f.create_time, f.create_by from t_folder f where parent_id = #{parentId} order by f.folder_name")
    List<TFolder> queryList(TFolder tFolder);


    /**
     * 查询文件属性
     */
    TFolder queryById(@Param("id") Long id, @Param("type") int type);


    @Insert("INSERT INTO t_folder(folder_name, create_time, create_by, type, file_url,parent_id) " +
            "VALUES (#{folderName}, #{createTime}, #{createBy}, #{type}, #{fileUrl}, #{parentId})")
    int insertFolder(TFolder tFolder);

    @Update("UPDATE t_folder SET folder_name=#{folderName} " +
            "WHERE folder_Id=#{folderId} and type=#{type}")
    int  updateById(TFolder tFolder);

    @Delete("delete from t_folder where folder_id=#{folderId}")
    int deleteById(Long folderId);
}
